<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
  <head>
    <th:block th:include="include :: header('党内制度详情')" />
    <style>
      .dangnei-content {
        padding: 20px;
        background: #fff;
        border-radius: 4px;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
      }
      .dangnei-title {
        font-size: 24px;
        font-weight: bold;
        text-align: center;
        margin-bottom: 20px;
        color: #c52222;
        border-bottom: 2px solid #c52222;
        padding-bottom: 15px;
      }
      .dangnei-meta {
        text-align: center;
        margin-bottom: 30px;
        color: #666;
        font-size: 14px;
      }
      .dangnei-text {
        line-height: 1.8;
        font-size: 16px;
        color: #333;
      }
      .dangnei-pdf,
      .dangnei-image {
        text-align: center;
        margin: 20px 0;
      }
      .dangnei-pdf iframe {
        width: 100%;
        height: 600px;
        border: 1px solid #ddd;
      }
      .dangnei-image img {
        max-width: 100%;
        height: auto;
        border: 1px solid #ddd;
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
      }
      .no-content {
        text-align: center;
        padding: 50px;
        color: #999;
        font-size: 18px;
      }
      .pdf-preview-fallback {
        padding: 20px;
        background: #f8f9fa;
        border: 1px solid #dee2e6;
        border-radius: 4px;
        margin: 20px 0;
      }
      .pdf-preview-fallback a {
        color: #007bff;
        text-decoration: none;
      }
      .pdf-preview-fallback a:hover {
        text-decoration: underline;
      }
    </style>
  </head>
  <body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
      <div class="row">
        <div class="col-sm-12">
          <div class="dangnei-content">
            <div class="dangnei-title" th:text="${djRedBook.title}">
              制度标题
            </div>
            <div class="dangnei-meta">
              <span
                >创建时间：<span
                  th:text="${#dates.format(djRedBook.createTime, 'yyyy-MM-dd HH:mm:ss')}"
                  >2023-01-01 12:00:00</span
                ></span
              >
              <span style="margin-left: 30px"
                >更新时间：<span
                  th:text="${#dates.format(djRedBook.updateTime, 'yyyy-MM-dd HH:mm:ss')}"
                  >2023-01-01 12:00:00</span
                ></span
              >
            </div>

            <!-- PDF内容 -->
            <div
              class="dangnei-pdf"
              th:if="${!#strings.isEmpty(djRedBook.bookUrl)}"
            >
              <iframe th:src="@{${djRedBook.bookUrl}}" frameborder="0"></iframe>
              <!-- 添加备用方案，如果iframe无法加载则提供下载链接 -->
              <div class="pdf-preview-fallback">
                <p>
                  如果PDF无法正常显示，请<a
                    th:href="@{${djRedBook.bookUrl}}"
                    target="_blank"
                    >点击此处下载PDF文件</a
                  >进行查看。
                </p>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <th:block th:include="include :: footer" />
    <script th:src="@{/ruoyi/js/study-time-recorder.js}"></script>
    <script th:inline="javascript">
      // 获取书籍ID
      var bookId = [[${djRedBook.id}]];

      // 开始学习记录
      StudyTimeRecorder.startBook(bookId, {
          onSuccess: function() {
              console.log("开始书籍学习记录: " + bookId);
          }
      });

      // 页面卸载时结束学习记录（使用同步方法）
      $(window).on('beforeunload', function() {
          if (StudyTimeRecorder.isStudying()) {
              StudyTimeRecorder.endSync();
          }
      });

      $(document).ready(function() {
          // 检查PDF是否加载成功
          $('.dangnei-pdf iframe').on('load', function() {
              try {
                  // 尝试访问iframe内容，如果失败说明加载有问题
                  var iframeDoc = this.contentDocument || this.contentWindow.document;
                  // 如果iframe内容为空或出错，显示备用方案
              } catch (e) {
                  // 跨域问题，无法检查内容，但不影响使用
              }
          }).on('error', function() {
              // iframe加载出错时的处理
              console.log('PDF加载出错');
          });
      });
    </script>
  </body>
</html>
